%Info of statistical Information.

%Image Processing Assignment - 5
%Name: - Kirtish Dhande
%Class: - B.E. - C
%Roll no: - 54
%This is the program to find mean, median, standard deviation and variance on intensities of an image.
%Date of assignment - 23/02/2016

%Variables declared -
% A - Has image intensities in double format.
% row - total x-coordinates of image.
% col - total y-coordinates of image.
% A1 - A 1-D array converted from 2-D array of intensities on image.
% Sum - has the total sum of intensities of image
% mean - has mean intensity of image.
% mid_A1 - It has total length of A1 array.
% median - It has the median value of the image.
% standard_Deviation - It has the standard deviation of intensities of image.
% variance - It has the variance of intensities of image.

 %image is read here
 clc;
 clear all;
 close all;
 A=imread('lena.bmp');

 %WE convert image to double format and find its total x,y coordinates.
A=double(A);
[row,col]=size(A);

%Here we calculate sum of intensities.
Sum=sum(A(:));
display(Sum);

%Here we find Mean intensity of image.
mean=(sum(A(:))/(row*col));
display(mean);

%Here we first convert 2-D matrix of image to 1-D for calculation.
%Then we sort the array, we find the length of it and thus,
% The middle value of array, which is the Median
A1 = (A(:));
A1 = sort(A1);
mid_A1 = length(A1);
median = A1(mid_A1/2);
display(median);

% medvalue - An 1-D array created for storing temporary data.
%Here we calculate the standard deviation of intensities of image.
medvalue = zeros(mid_A1,1);
for i = 1:mid_A1
    medvalue(i,1) = ((A1(i) - mean)^2);
end
standard_Deviation = sqrt(sum(medvalue)/mid_A1);
display(standard_Deviation);

%Here we calculate the variance of intensities of image.
variance = (standard_Deviation)^2;
display(variance);